package main

import "fmt"

type Human struct {
	name string
	sex  string
}

func (this *Human) eat() {
	fmt.Println("Human eat")
}
func (this *Human) walk() {
	fmt.Println("Human walk")
}

// 继承
type Superman struct {
	Human // 表示继承了Human类的方法
	level int
}

// 覆盖父类Human的eat方法
func (this *Superman) eat() {
	fmt.Println("Superman eat")
}

// 子类新方法
func (this *Superman) fly() {
	fmt.Println("Superman fly")
}

func (this *Superman) print() {
	fmt.Print("name = ", this.name)
	fmt.Print(", sex = ", this.sex)
	fmt.Print(", level = ", this.level)
	fmt.Println("")
}

func main() {
	human := Human{"zhangsan", "man"}
	human.eat()
	human.walk()

	fmt.Println("-----------------定义子类对象，定义同时初始化-----------------")
	// 定义一个子类对象，先实现父类对象，在实现定义子类对象
	superman := Superman{Human{"clark", "man"}, 100}
	superman.eat()
	superman.walk()
	superman.fly()
	superman.print()

	fmt.Println("-----------------定义子类对象，先声明对象，后初始化-----------------")
	var superWoman Superman
	superWoman.name = "superwoman"
	superWoman.sex = "woman"
	superWoman.level = 90
	superWoman.print()
}
